package models;

import java.io.Serializable;
import javax.persistence.*;

import org.apache.commons.lang3.StringUtils;

import prefix.util.DateUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the employment database table.
 * 
 */
@Entity
@Table(name = "EMPLOYMENT")
public class Employment implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "EMPLOYMENT_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "EMPLOYMENT_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "EMPLOYMENT_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private Integer aid;

    @Column(name = "APPLICATNT_SHARE")
    private double applicatntShare;

    @Column(name = "COMPANY_PHONE")
    private String companyPhone;

    @Column(name = "COMPANY_PHONE_EXT")
    private String companyPhoneExt;

    @Column(name = "COMPANY_SEGMENT")
    private int companySegment;

    @Column(name = "COMPANY_SIZE")
    private int companySize;

    @Column(name = "COMPANY_TYPE")
    private int companyType;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(name = "EMP_NAME", length = 100)
    private String empName;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "END_D")
    private Date endD;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ESTABLISH_D")
    private Date establishD;

    @Column(name = "LAWSUIT_STATE")
    private int lawsuitState;

    @Column(name = "LOAN_STATE")
    private int loanState;

    @Column(name = "MORTGAGE_STATE")
    private int mortgageState;

    @Column(name = "NET_MARGIN")
    private double netMargin;

    @Column(name = "OPT_COST")
    private double optCost;

    @Column(name = "OPT_INCOME")
    private double optIncome;

    @Column(name = "ORG_CODE", length = 100)
    private String orgCode;

    @Column(name = "PAID_TAX_STATE")
    private int paidTaxState;

    @Column(name = "REG_NUM", length = 100)
    private String regNum;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "START_D")
    private Date startD;

    private int status;

    @Column(length = 50)
    private String title;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    @Column(length = 200)
    private String url;

    public Employment() {
    }

    public void setValues(int aid, Employment.Status employmentStatus, String companyName, String jobTitle,
            int jobTenureYears, String website, Employment.CompanySegment companySegment,
            Employment.CompanyType companyType, Employment.CompanySize companySize, Date establishDate,
            Double applicantShare, String orgCode, String regNO, Double optIncome, Double optCost, Double profit,
            State loanState, State mortgageState, State lawsuitState, State paidTaxState) {
        if (aid > 0)
            this.setAid(aid);
        if (employmentStatus != null)
            this.setStatus(employmentStatus);
        if (StringUtils.isNotEmpty(companyName))
            this.setEmpName(companyName);
        if (StringUtils.isNotEmpty(jobTitle))
            this.setTitle(jobTitle);
        if (jobTenureYears > 0)
            setStartD(DateUtil.addYears(new Date(), -jobTenureYears));
        if (StringUtils.isNotEmpty(website))
            setUrl(website);
        if (companySegment != null)
            setCompanySegment(companySegment);
        if (companyType != null)
            setCompanyType(companyType);
        if (companySize != null)
            setCompanySize(companySize);
        if (establishDate != null)
            setEstablishD(establishDate);
        if (applicantShare != null)
            this.setApplicatntShare(applicatntShare);
        if (StringUtils.isNotEmpty(orgCode))
            this.setOrgCode(orgCode);
        if (StringUtils.isNotEmpty(regNO))
            this.setRegNum(regNO);
        if (optIncome != null)
            this.setOptIncome(optIncome);
        if (optCost != null)
            this.setOptCost(optCost);
        if (profit != null)
            this.setNetMargin(profit);
        if (loanState != null)
            this.setLoanState(loanState);
        if (mortgageState != null)
            this.setMortgageState(mortgageState);
        if (lawsuitState != null)
            this.setLawsuitState(lawsuitState);
        if (paidTaxState != null)
            this.setPaidTaxState(paidTaxState);
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAid() {
        return this.aid;
    }

    public void setAid(Integer aid) {
        this.aid = aid;
    }

    public double getApplicatntShare() {
        return this.applicatntShare;
    }

    public void setApplicatntShare(double applicatntShare) {
        this.applicatntShare = applicatntShare;
    }

    public String getCompanyPhone() {
        return this.companyPhone;
    }

    public void setCompanyPhone(String companyPhone) {
        this.companyPhone = companyPhone;
    }

    public CompanySegment getCompanySegment() {
        return CompanySegment.values()[this.companySegment];
    }

    public void setCompanySegment(CompanySegment companySegment) {
        this.companySegment = companySegment.ordinal();
    }

    public CompanySize getCompanySize() {
        return CompanySize.values()[this.companySize];
    }

    public void setCompanySize(CompanySize companySize) {
        this.companySize = companySize.ordinal();
    }

    public CompanyType getCompanyType() {
        return CompanyType.values()[this.companyType];
    }

    public void setCompanyType(CompanyType companyType) {
        this.companyType = companyType.ordinal();
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public String getEmpName() {
        return this.empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public Date getEndD() {
        return this.endD;
    }

    public void setEndD(Date endD) {
        this.endD = endD;
    }

    public Date getEstablishD() {
        return this.establishD;
    }

    public void setEstablishD(Date establishD) {
        this.establishD = establishD;
    }

    public State getLawsuitState() {
        return State.values()[this.lawsuitState];
    }

    public void setLawsuitState(State lawsuitState) {
        this.lawsuitState = lawsuitState.ordinal();
    }

    public State getLoanState() {
        return State.values()[this.loanState];
    }

    public void setLoanState(State loanState) {
        this.loanState = loanState.ordinal();
    }

    public State getMortgageState() {
        return State.values()[this.mortgageState];
    }

    public void setMortgageState(State mortgageState) {
        this.mortgageState = mortgageState.ordinal();
    }

    public double getNetMargin() {
        return this.netMargin;
    }

    public void setNetMargin(double netMargin) {
        this.netMargin = netMargin;
    }

    public double getOptCost() {
        return this.optCost;
    }

    public void setOptCost(double optCost) {
        this.optCost = optCost;
    }

    public double getOptIncome() {
        return this.optIncome;
    }

    public void setOptIncome(double optIncome) {
        this.optIncome = optIncome;
    }

    public String getOrgCode() {
        return this.orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public State getPaidTaxState() {
        return State.values()[this.paidTaxState];
    }

    public void setPaidTaxState(State paidTaxState) {
        this.paidTaxState = paidTaxState.ordinal();
    }

    public String getRegNum() {
        return this.regNum;
    }

    public void setRegNum(String regNum) {
        this.regNum = regNum;
    }

    public Date getStartD() {
        return this.startD;
    }

    public void setStartD(Date startD) {
        this.startD = startD;
    }

    public Status getStatus() {
        return Status.values()[this.status];
    }

    public void setStatus(Status status) {
        this.status = status.ordinal();
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCompanyPhoneExt() {
        return companyPhoneExt;
    }

    public void setCompanyPhoneExt(String companyPhoneExt) {
        this.companyPhoneExt = companyPhoneExt;
    }

    public static enum Status {
        ANY("INTERNAL"), // 0 - internal to be used for admin app only
        UNEMPLOYED("Unemployed"),
        EMPLOYED("Employed"),
        SELFEMPLOYED("Self-employed"),
        RETIRED("Retired"),
        STUDENT("Student"),
        OTHER("Other"),
        PART_TIME("Part Time"),
        CONTRACTOR("Contractor"),
        DISABLED("Disabled (or on Disability)"), ;

        private String _label;

        private Status(String label) {
            this._label = label;
        }

        public String getLabel() {
            return this._label;
        }

        public static Employment.Status[] getTraderAgreementValues() {
            Employment.Status[] emp = new Employment.Status[7];
            for (int i = 0; i < 7; i++) {
                emp[i] = Employment.Status.values()[i];
            }
            return emp;
        }

        public static Employment.Status getStatus(String c) {
            for (Employment.Status s : Employment.Status.values())
                if (s.toString().equalsIgnoreCase(c))
                    return s;
            return null;
        }

        public static List<Employment.Status> getEmploymentStatusList() {
            List<Employment.Status> empStatusList = new ArrayList<Employment.Status>();
            for (int i = 0; i < Employment.Status.values().length; i++) {
                if (!Employment.Status.values()[i].getLabel().toString().equals("INTERNAL")) {
                    empStatusList.add(Employment.Status.values()[i]);
                }
            }
            return empStatusList;
        }
    }

    public enum CompanySegment {
        RETAIL,
        INFORMATION_TECHNOLOGY,
        COMMUNICATION_ELECTRONICS,
        FINANCIAL,
        RESTAURANT,
        BIO_PHARMACEUTICAL,
        HEALTH,
        INFORMATION_MEDIA,
        ART,
        CONSTRUCTION_REAL_ESTATE,
        CONSULTING,
        LAW,
        EDUCATION_RESEARCH,
        SERVICES,
        TOURISM,
        MANUFACTURING,
        GOVERNMENT_AGENCY,
        TRANSPORTATION,
        ENTERTAINMENT_SPORTS,
        AGRICULTURAL_FORESTRY_FISHING,
        OTHER,
    }

    public enum CompanyType {
        GOVERNMENT_AGENCY,
        LOCAL_GOVERNMENT,
        EDUCATION,
        MILITARY,
        SELF_EMPLOYED,
        PRIVATE,
        PUBLICLY_TRADED,
        CHINESE_FOREIGN_JOINT_VENTURE,
        WHOLLY_FOREIGN_OWNED_ENTERPRISE,
        LOCAL_COMMUNAL_ENTERPRISE,
        SOE,
        OTHER;
    }

    public enum CompanySize {
        LESS_THAN_10("LT10"),
        FROM_10_TO_19("10-19"),
        FROM_20_TO_49("20-49"),
        FROM_50_TO_99("50-99"),
        FROM_100_TO_199("100-199"),
        FROM_200_TO_299("200-299"),
        FROM_300_TO_499("300-499"),
        FROM_500_TO_999("500-999"),
        MORE_THAN_1000("MT1000"), ;
        private String _label;

        private CompanySize(String label) {
            this._label = label;
        }

        public String getLabel() {
            return this._label;
        }
    }

    public enum State {
        YES("是"), //
        NO("否");
        private String _label;

        State(String label) {
            this._label = label;
        }

        public String getLabel() {
            return this._label;
        }

        public static State getStateByLabel(String label) {
            for (State item : State.values()) {
                if (item.getLabel().equals(label)) {
                    return item;
                }
            }
            return null;
        }
    }

}